import 'package:xsdk_flutter/xsdk_splashAd.dart';
import 'package:xsdk_flutter/xsdk_videoAd.dart';

import 'xsdk_flutter_platform_interface.dart';
import 'xsdk_banner.dart';

class XSdk {
  XSdk._privateConstructor() {
    //todo 私有构造方法
  }

  static final XSdk _instance = XSdk._privateConstructor();

  factory XSdk() {
    return _instance;
  }

  Future<String?> getPlatformVersion() {
    return XsdkFlutterPlatform.instance.getPlatformVersion();
  }

  void onPush({
    required EventHandler onRegisterSucceed,
    required EventHandler onNotificationMessageClicked,
    required EventHandler onNotificationMessageArrived,
  }) {
    XsdkFlutterPlatform.instance.onPush(
        onRegisterSucceed: onRegisterSucceed,
        onNotificationMessageClicked: onNotificationMessageClicked,
        onNotificationMessageArrived: onNotificationMessageArrived);
  }

  Future<bool?> hasSDK({required String service, required String provider}) {
    return XsdkFlutterPlatform.instance
        .hasSDK(service: service, provider: provider);
  }

  Future<bool?> isInitSDK({required String service, required String provider}) {
    return XsdkFlutterPlatform.instance
        .isInitSDK(service: service, provider: provider);
  }

  Future<void> init() {
    return XsdkFlutterPlatform.instance.init();
  }

  Future<String?> initSDK(Map data) {
    return XsdkFlutterPlatform.instance.initSDK(data);
  }

  // 是否存在某个sdk
  Future<String?> login(Map data) {
    return XsdkFlutterPlatform.instance.login(data);
  }

  Future<String?> logout(Map data) {
    return XsdkFlutterPlatform.instance.logout(data);
  }

  Future<String?> pay(Map data) {
    return XsdkFlutterPlatform.instance.pay(data);
  }

  Future<String?> finishPay(Map data) {
    return XsdkFlutterPlatform.instance.finishPay(data);
  }

  //=======================内购类的==================================
  Future<String?> requestProduct(Map data) {
    return XsdkFlutterPlatform.instance.requestProduct(data);
  }

  Future<String?> queryProduct(Map data) {
    return XsdkFlutterPlatform.instance.queryProduct(data);
  }

  void onIPAEvent({void Function(Map)? onEvent}) {
    XsdkFlutterPlatform.instance.onIPAEvent(onEvent: onEvent);
  }
  //================================================================

  Future<String?> share(Map data) {
    return XsdkFlutterPlatform.instance.share(data);
  }

  Future<void> postEvent(Map data) {
    return XsdkFlutterPlatform.instance.postEvent(data);
  }

  Future<BannerAd?> createBannerAd(Map data,
      {void Function(String)? onLoad,
      void Function()? onHide,
      void Function(String)? onError}) {
    return XsdkFlutterPlatform.instance
        .createBannerAd(data, onLoad: onLoad, onHide: onHide, onError: onError);
  }

  Future<VideoAd?> createVideoAd(Map data,
      {void Function(String)? onLoad,
      void Function()? onReward,
      void Function()? onClose,
      void Function(String)? onError}) {
    return XsdkFlutterPlatform.instance.createVideoAd(data,
        onLoad: onLoad, onClose: onClose, onError: onError, onReward: onReward);
  }

  Future<SplashAd?> createSplashAd(Map data,
      {void Function(String)? onLoad,
      void Function()? onClicked,
      void Function()? onDismissed,
      void Function(String)? onError}) {
    return XsdkFlutterPlatform.instance.createSplashAd(data,
        onLoad: onLoad,
        onClicked: onClicked,
        onError: onError,
        onDismissed: onDismissed);
  }
}
